﻿Imports System.Data.Entity
Imports System.Data.Objects
Imports System.Data.Objects.DataClasses
Imports System.Data.EntityClient
Imports System.ComponentModel
Imports System.Xml.Serialization
Imports System.Runtime.Serialization

Namespace Models


    Public Class VoteNumsContext
        Inherits DbContext
        ' You can add custom code to this file. Changes will not be overwritten.
        ' 
        ' If you want Entity Framework to drop and regenerate your database
        ' automatically whenever you change your model schema, add the following
        ' code to the Application_Start method in your Global.asax file.
        ' Note: this will destroy and re-create your database with every model change.
        ' 
        ' System.Data.Entity.Database.SetInitializer(New System.Data.Entity.DropCreateDatabaseIfModelChanges(Of Models.VoteNumsContext)())

        Public Sub New()
            Dim UriString = ConfigurationManager.AppSettings("SQLSERVER_URI")
            Dim uri = New Uri(UriString)
            Dim connectionString = New System.Data.SqlClient.SqlConnectionStringBuilder() With { _
              .DataSource = uri.Host, _
              .InitialCatalog = uri.AbsolutePath.Trim("/"c), _
              .UserID = uri.UserInfo.Split(": ").First(), _
              .Password = uri.UserInfo.Split(": ").Last() _
              }.ConnectionString
            Me.Configuration.LazyLoadingEnabled() = True

        End Sub
 



        Public Property VoteNums As DbSet(Of VoteNum)
    End Class

    Public Class VoteNum
        Public Property VoteNumId() As Integer
        Public Property President() As Integer
        Public Property VicePresident() As Integer
        Public Property Secretary() As Integer
        Public Property Treasurer() As Integer
        Public Property SergeantAtArms As Integer


    End Class

            Public Class MakeNumVote
                Public Function createVote()
                    Dim position As Integer = 0
                    Dim listOfVotes As New List(Of Integer)
                    Dim newRandom As New Random
                    While position < 5
                        Dim RandomNumber = (newRandom.Next(1, 11)) / 10.0
                        Dim RandomPerson As Integer = vbNull
                        If RandomNumber <= 0.2 Then
                            RandomPerson = 0
                        ElseIf RandomNumber > 0.2 And RandomNumber <= 0.4 Then
                            RandomPerson = 1
                        ElseIf RandomNumber > 0.4 And RandomNumber <= 0.6 Then
                            RandomPerson = 2
                        ElseIf RandomNumber > 0.6 And RandomNumber <= 0.8 Then
                            RandomPerson = 3
                        ElseIf RandomNumber > 0.8 And RandomNumber <= 1.0 Then
                            RandomPerson = 4
                        End If
                        position = position + 1
                        listOfVotes.Add(RandomPerson)
                    End While
                    Return listOfVotes
                End Function
            End Class

End Namespace
